
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
request.setAttribute("decorator", "none");
response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
%>

<link href="css/redragon.css" rel="stylesheet">

<%-- 导入面包屑 --%>
<jsp:include page="../common/nav.jsp"></jsp:include>

<div class="wrapper wrapper-content animated fadeInRight">

	<%-- 导入提示信息框 --%>
    <c:if test="${hint!=null&&hint!=''}">
   		<jsp:include page="../common/alert/alert.jsp">
   			<jsp:param value="${hint}" name="alertType"/>
   			<jsp:param value="${alertMessage}" name="alertMessage"/>
   		</jsp:include>
    </c:if>

	<div class="row">
		<div class="col-lg-12">
			<div class="ibox ">
				<div class="ibox-title btn-success btn-outline panel-success collapse-link" title="展开/收起">
					<h5>分类账&nbsp;<span style="color: black;">（<i class="fa fa-tag"></i>${requestScope.approveStatusMap[requestScope.gLLedger.approveStatus]}）</span></h5>
					<div class="ibox-tools">
						<i class="fa fa-chevron-up"></i> 
					</div>
				</div>

				<form id="form" action="web/gLLedger/editGLLedger" method="post">
					
					<div class="ibox-content border-bottom">
					    <div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span><strong>分类账编码</strong></label>
							<div class="col-sm-4">
								<input id="ledgerCode" name="ledgerCode" type="text" class="form-control" value="${requestScope.gLLedger.ledgerCode}">
							</div>
							
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span><strong>分类账名称</strong></label>
							<div class="col-sm-4">
								<input id="ledgerName" name="ledgerName" type="text" class="form-control" value="${requestScope.gLLedger.ledgerName}">
							</div>
						</div>
						<div class="hr-line-dashed"></div>
						
						
						<div class="form-group row">
	                        <label class="col-sm-2 col-form-label"><strong>分类账描述</strong></label>
							<div class="col-sm-4">
								<input id="ledgerDesc" name="ledgerDesc" type="text" class="form-control" value="${requestScope.gLLedger.ledgerDesc}">
							</div>
							
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span><strong>状态</strong></label>
	                        <div class="col-sm-4">
		                        <select class="form-control" name="status" id="status">
		                            <option value="Y" selected="selected">有效</option>
		                            <option value="N">无效</option>
		                        </select>
	                        </div>
	                    </div>
	                    <div class="hr-line-dashed"></div>
	                    
	                    <div class="form-group row">
	                        <label class="col-sm-2 col-form-label"><span class="text-danger">*</span><strong>会计日历</strong></label>
	                        <div class="col-sm-4">
		                        <select class="form-control" name="calendarCode" id="calendarCode">
		                        	<option value="" selected="selected">请选择...</option>
		                        	<c:forEach items="${requestScope.calendarList}" var="calendar">
		                        		<option value="${calendar.calendarCode}">${calendar.calendarName}</option>
		                        	</c:forEach>
		                        </select>
	                        </div>

	                        <label class="col-sm-2 col-form-label"><span class="text-danger">*</span><strong>币种</strong></label>
	                        <div class="col-sm-4">
		                        <select class="form-control" name="currencyCode" id="currencyCode">
		                        	<option value="" selected="selected">请选择...</option>
		                        	<c:forEach items="${requestScope.currencyTypeMap}" var="currencyType">
		                        		<option value="${currencyType.key}">${currencyType.value}</option>
		                        	</c:forEach>
		                        </select>
	                        </div>
	                    </div>
	                    <div class="hr-line-dashed"></div>
	                    
	                    <div class="form-group row">
	                        <label class="col-sm-2 col-form-label"><span class="text-danger">*</span><strong>会计方法</strong></label>
	                        <div class="col-sm-4">
	                        <select class="form-control" name="accountingMethod" id="accountingMethod">
	                        	<option value="" selected="selected">请选择...</option>
	                        	<c:forEach items="${requestScope.accountingMethodMap}" var="accountingMethod">
	                        		<option value="${accountingMethod.key}">${accountingMethod.value}</option>
	                        	</c:forEach>
	                        </select>
	                        </div>

	                        <label class="col-sm-2 col-form-label"><span class="text-danger">*</span><strong>主分类账标识</strong></label>
	                        <div class="col-sm-4">
		                        <select class="form-control" name="primaryFlag" id="primaryFlag">
		                        	<option value="" selected="selected">请选择...</option>
		                            <option value="Y">主分类账</option>
		                            <option value="N">辅助分类账</option>
		                        </select>
	                        </div>
	                    </div>
	                    <div class="hr-line-dashed"></div>
	                    
	                    <div class="form-group row">
	                        <label class="col-sm-2 col-form-label"><span class="text-danger">*</span><strong>启用时间</strong></label>
	                        <div class="col-sm-4">
		                        <select class="form-control" name="startupType" id="startupType">
		                        	<option value="" selected="selected">请选择...</option>
		                            <option value="YEAR_BEGIN">年初启用</option>
		                            <option value="YEAR_MIDDLE">年中启用</option>
		                        </select>
	                        </div>
	                    </div>
	                </div>
	                    
	                <div id="segmentDiv" class="ibox-content border-bottom">
						<fieldset>
							<legend class="text-info" style="font-size: inherit;"><i class="fa fa-th"></i> 会计科目结构</legend>
                           	
                           	<div class="form-group row" style="margin-left: 15px; margin-right: 15px;">
                           	
                           		<c:forEach begin="1" end="15" var="num">
	                            	<label id="segmentLabel${num}" class="col-sm-2 col-form-label">段值${num}（segment${num}）</label>
	                                <div class="col-sm-10">
	                                	<select class="form-control" name="segment${num}" id="segment${num}">
				                        	<option value="" selected="selected">请选择...</option>
				                        	<c:forEach items="${requestScope.accountingSubjectSegmentTypeMap}" var="accountingSubjectSegmentType">
				                        		<option value="${accountingSubjectSegmentType.key}">${accountingSubjectSegmentType.value}</option>
				                        	</c:forEach>
				                        </select>
	                                </div><br/><br/>
                                </c:forEach>
                                
                           	</div>
                        </fieldset>
                    </div>
	                    
	                <div class="ibox-content border-bottom">
						<div class="form-group row">
							<div class="col-sm-12 col-sm-offset-2 text-right">
								<button class="btn btn-white btn-lg" type="button" onclick="window.location.href='web/gLLedger/getGLLedgerList'">返回</button>&nbsp;
								<c:if test="${param.ledgerCode==null||param.ledgerCode==''||requestScope.gLLedger.approveStatus=='UNSUBMIT'||requestScope.gLLedger.approveStatus=='REJECT' }">
									<button class="ladda-button ladda-button-demo btn btn-success btn-lg" data-style="expand-right">&nbsp;&nbsp;保存&nbsp;&nbsp;<i class="fa fa-save"></i></button>
								</c:if>
								
								<c:if test="${param.ledgerCode!=null&&param.ledgerCode!=''}">
									<c:if test="${requestScope.gLLedger.approveStatus=='UNSUBMIT'||requestScope.gLLedger.approveStatus=='REJECT' }">
										<button class="btn btn-primary btn-lg" type="button" onclick="window.location.href='web/gLLedger/updateApproveStatus?code=${requestScope.gLLedger.ledgerCode}&approveStatus=SUBMIT'">&nbsp;&nbsp;提交&nbsp;&nbsp;<i class="fa fa-arrow-circle-right"></i></button>&nbsp;
									</c:if>
									<c:if test="${requestScope.gLLedger.approveStatus=='SUBMIT' }">
										<button class="btn btn-warning btn-lg btn-redragon-approve" type="button" onclick="approveData()">&nbsp;&nbsp;审核通过&nbsp;&nbsp;<i class="fa fa-check-circle"></i></button>&nbsp;
										<button class="btn btn-danger btn-lg btn-redragon-approve" type="button" onclick="window.location.href='web/gLLedger/updateApproveStatus?code=${requestScope.gLLedger.ledgerCode}&approveStatus=REJECT'">&nbsp;&nbsp;驳回&nbsp;&nbsp;<i class="fa fa-times-circle"></i></button>&nbsp;
									</c:if>
									<c:if test="${requestScope.gLLedger.approveStatus=='APPROVE' }">
										<button class="btn btn-success btn-lg" type="button" onclick="alterData()">&nbsp;&nbsp;变更&nbsp;&nbsp;<i class="fa fa-retweet"></i></button>&nbsp;
									</c:if>
								</c:if>
							</div>
						</div>
						
						<input type="hidden" id="ledgerId" name="ledgerId" value="${requestScope.gLLedger.ledgerId}">
						<input type="hidden" name="createdDate" value="${requestScope.gLLedger.createdDate}">
						<input type="hidden" name="createdBy" value="${requestScope.gLLedger.createdBy}">
					
					</div>
				</form>
				
			</div>
		</div>
	</div>
</div>

<!-- select2 -->
<script src="js/plugins/select2/select2.full.min.js"></script>

<script>
	$(document).ready(function() {
		//初始化status
		if("${requestScope.gLLedger.status}"!=""){
			$("#status").val("${requestScope.gLLedger.status}");
		}
		//初始化calendarCode
		if("${requestScope.gLLedger.calendarCode}"!=""){
			$("#calendarCode").val("${requestScope.gLLedger.calendarCode}");
		}
		//初始化currencyCode
		if("${requestScope.gLLedger.currencyCode}"!=""){
			$("#currencyCode").val("${requestScope.gLLedger.currencyCode}");
		}
		//初始化accountingMethod
		if("${requestScope.gLLedger.accountingMethod}"!=""){
			$("#accountingMethod").val("${requestScope.gLLedger.accountingMethod}");
		}
		//初始化primaryFlag
		if("${requestScope.gLLedger.primaryFlag}"!=""){
			$("#primaryFlag").val("${requestScope.gLLedger.primaryFlag}");
		}
		//初始化startupType
		if("${requestScope.gLLedger.startupType}"!=""){
			$("#startupType").val("${requestScope.gLLedger.startupType}");
		}
		
		//初始化segment
		if("${requestScope.gLLedger.segment1}"!=""){
			$("#segment1").val("${requestScope.gLLedger.segment1}");
			$("#segmentLabel1").addClass("text-info");
		}
		if("${requestScope.gLLedger.segment2}"!=""){
			$("#segment2").val("${requestScope.gLLedger.segment2}");
			$("#segmentLabel2").addClass("text-info");
		}
		if("${requestScope.gLLedger.segment3}"!=""){
			$("#segment3").val("${requestScope.gLLedger.segment3}");
			$("#segmentLabel3").addClass("text-info");
		}
		if("${requestScope.gLLedger.segment4}"!=""){
			$("#segment4").val("${requestScope.gLLedger.segment4}");
			$("#segmentLabel4").addClass("text-info");
		}
		if("${requestScope.gLLedger.segment5}"!=""){
			$("#segment5").val("${requestScope.gLLedger.segment5}");
			$("#segmentLabel5").addClass("text-info");
		}
		if("${requestScope.gLLedger.segment6}"!=""){
			$("#segment6").val("${requestScope.gLLedger.segment6}");
			$("#segmentLabel6").addClass("text-info");
		}
		if("${requestScope.gLLedger.segment7}"!=""){
			$("#segment7").val("${requestScope.gLLedger.segment7}");
			$("#segmentLabel7").addClass("text-info");
		}
		if("${requestScope.gLLedger.segment8}"!=""){
			$("#segment8").val("${requestScope.gLLedger.segment8}");
			$("#segmentLabel8").addClass("text-info");
		}
		if("${requestScope.gLLedger.segment9}"!=""){
			$("#segment9").val("${requestScope.gLLedger.segment9}");
			$("#segmentLabel9").addClass("text-info");
		}
		if("${requestScope.gLLedger.segment10}"!=""){
			$("#segment10").val("${requestScope.gLLedger.segment10}");
			$("#segmentLabel10").addClass("text-info");
		}
		if("${requestScope.gLLedger.segment11}"!=""){
			$("#segment11").val("${requestScope.gLLedger.segment11}");
			$("#segmentLabel11").addClass("text-info");
		}
		if("${requestScope.gLLedger.segment12}"!=""){
			$("#segment12").val("${requestScope.gLLedger.segment12}");
			$("#segmentLabel12").addClass("text-info");
		}
		if("${requestScope.gLLedger.segment13}"!=""){
			$("#segment13").val("${requestScope.gLLedger.segment13}");
			$("#segmentLabel13").addClass("text-info");
		}
		if("${requestScope.gLLedger.segment14}"!=""){
			$("#segment14").val("${requestScope.gLLedger.segment14}");
			$("#segmentLabel14").addClass("text-info");
		}
		if("${requestScope.gLLedger.segment15}"!=""){
			$("#segment15").val("${requestScope.gLLedger.segment15}");
			$("#segmentLabel15").addClass("text-info");
		}
		
		//初始化ledgerCode只读
		if("${requestScope.gLLedger.ledgerCode}"!=""){
			$("#ledgerCode").prop("readonly", true);
		}
	
		//初始化select2
		$('.select2').select2({width: "100%"});
		
		//初始化切换主分类账标识效果
		initPrimaryFlag();
		
		//切换主分类账标识效果
		$("#primaryFlag").change(function(){
			initPrimaryFlag();
		});
		
		
		
		//表单提交
		var l = $('.ladda-button-demo').ladda();

		l.click(function() {
			$("#form").valid();
			//l.ladda('stop');
		});

		$("#form").validate({
			rules : {
				ledgerCode : {
					required : true,
					isCode : true,
				},
				ledgerName : {
					required : true,
				},
				currencyCode : {
					required : true,
				},
				calendarCode : {
					required : true,
				},
				accountingMethod : {
					required : true,
				},
				primaryFlag : {
					required : true,
				},
				status : {
					required : true,
				},
			},
			submitHandler: function(form) {
				l.ladda('start');
		        form.submit();
		    }
		});
		
	});
	
	
	
	//审批通过
	function approveData(){
		redragonJS.confirm("确认审批通过？", function(){
			window.location.href='web/gLLedger/updateApproveStatus?code=${requestScope.gLLedger.ledgerCode}&approveStatus=APPROVE';
		});
	}
	
	//数据变更
	function alterData(){
		redragonJS.confirm("确认变更数据？数据变更可能会影响到已有的业务！", function(){
			window.location.href='web/gLLedger/updateApproveStatus?code=${requestScope.gLLedger.ledgerCode}&approveStatus=UNSUBMIT';
		});
	}
	
	//初始化主分类账切换效果
	function initPrimaryFlag(){
		if($("#primaryFlag").val()=="Y"){
			$("#segmentDiv").show();
		}else{
			$("#segmentDiv").hide();
		}
	}
	
</script>